// components/setText/index.js
Component({

    /**
     * 组件的属性列表
     */
    properties: {
        show: {
            type: Boolean,
            default: false
        },
        title: {
            type: String,
            default: '设置人均单价'
        },
        label: {
            type: String,
            default: '人均单价'
        },
        empty: {
            type: Boolean,
            default: true
        },
        tips: {
            type: String,
            default: '请输入内容'
        },
        value: {
            type: Number,
            default: 0
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        newValue: ''
    },
    observers: {
        'show': function(){
            this.setData({
                newValue: this.data.value
            })
        },
        
    },
    /**
     * 组件的方法列表
     */
    methods: {
        //设置值
        setValue: function(e) {
            let v = Number(e.detail);
            this.setData({
                newValue: v
            })
        },
        //关闭
        close: function() {
            this.triggerEvent('confirm');  
        },
        //保存
        save: function() {
            let {newValue,tips,empty} = this.data;
            if(!empty && newValue<=0){
                wx.showToast({
                    title: tips,
                    icon: 'none'
                })
                return;
            }
            this.triggerEvent('confirm',{change: true, value: newValue});  
        }
    }
})